<?php
class SiteController extends AdminController{
    public function indexAction(){
        $option = Request::asget(6,'option','');
        if($option == ''){
            return true;
        }else{
            $site = new SiteModel;
            $data = $site->where(['options'=>$option])->one();
            // Yaf_Dispatcher::getInstance()->disableView();
            $this->_view->site = $data;
            // $this->display('site-edit',$data);
        }
                                 
    }
    // Mark...
    public function insertAction(){
        Yaf_Dispatcher::getInstance()->disableView();
        $option = Request::aspost(6,'option');
        $data['title'] = Request::aspost(6,'title','');
        $data['keyword'] = Request::aspost(6,'keyword','');
        $data['logo'] = Request::aspost(6,'logo','');
        $data['description'] = Request::aspost(6,'description','');
        $data['copyright'] = Request::aspost(6,'copyright','');
        $data['ipc'] = Request::aspost(6,'ipc','');
        $values = json_encode($data);
        $data = [];
        $data['values'] = $values;
        $data['option'] = $option;
        $site = new SiteModel;
        $flag = $site->insert($data);
        if($flag == false){
            Response::error('wrong');
        }else{
            Response::success('nice');
        }

    }
    public function updateAction(){
        Yaf_Dispatcher::getInstance()->disableView();
        $option = Request::aspost(6,'option');
        $data['title'] = Request::aspost(6,'title','');
        $data['keyword'] = Request::aspost(6,'keyword','');
        $data['logo'] = Request::aspost(6,'logo','');
        $data['description'] = Request::aspost(6,'description','');
        $data['copyright'] = Request::aspost(6,'copyright','');
        $data['ipc'] = Request::aspost(6,'ipc','');
        $values = json_encode($data);
        $data = [];
        $data['vals'] = $values;
        $data['options'] = $option;
        $site = new SiteModel;
        $temp = $site->where(['options' => $option])->one();
        if(empty($temp)){
            $flag = $site->insert($data);
        }else{
            $flag = $site->where(['options' => $option])->update($data);
        }
        if($flag === false){
            Response::error('wrong');
        }else{
            Response::success('nice');
        }

    }
    public function logoAction(){
        Yaf_Dispatcher::getInstance()->disableView();
        $up = new Upload;
        $up->save_path = 'logo';
        $file = $up->upload();
        Response::work($file);
    }
    public function generalAction(){
        $option = Request::asget(6,'option');
        if($option == '1'){
            return true;
        }else{
            $site = new SiteModel;
            $data = $site->where(['options'=>$option])->one();
            // Yaf_Dispatcher::getInstance()->disableView();
            $this->_view->site = $data;
            // $this->display('site-edit',$data);
        }
    }
    public function upgeneralAction(){
        Yaf_Dispatcher::getInstance()->disableView();
        $option = Request::aspost(6,'option');
        $data['register'] = Request::aspost(6,'register','');
        $data['page'] = Request::aspost(3,'page',10);
        $values = json_encode($data);
        $data = [];
        $data['vals'] = $values;
        $data['options'] = $option;
        $site = new SiteModel;
        $temp = $site->where(['options' => $option])->one();
        if(empty($temp)){
            $flag = $site->insert($data);
        }else{
            $flag = $site->where(['options' => $option])->update($data);
        }
        if($flag === false){
            Response::error('wrong');
        }else{
            Response::success('nice');
        }
    }
}